// pages/cate/cate.js
import {
  getCateAPI
} from '../../api/cate'
import {
  getProductsByCateIdAPI
} from '../../api/product'

const swiperList = [
  `https://lionkliu-typore.oss-cn-shanghai.aliyuncs.com/blog-img/202404171110233.jpeg`,
  `https://lionkliu-typore.oss-cn-shanghai.aliyuncs.com/blog-img/202404171111662.png`,
  `https://lionkliu-typore.oss-cn-shanghai.aliyuncs.com/blog-img/202404171114535.png`,
  `https://lionkliu-typore.oss-cn-shanghai.aliyuncs.com/blog-img/202404171115702.jpeg`,
  `https://lionkliu-typore.oss-cn-shanghai.aliyuncs.com/blog-img/202404171116194.jpeg`,
];

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  onLoad(options) {

  },

})

Component({
  data: {
    cateList: [],
    productList: [],
    swiperList

  },
  methods: {
    onLoad: function (options) {
      this.getCateList()
      this.getProductsByCateId(1)
    },
    async getCateList() {
      const {
        result
      } = await getCateAPI();
      this.setData({
        cateList: result,
      })
    },
    async getProductsByCateId(id) {
      const {
        result
      } = await getProductsByCateIdAPI(id);
      this.setData({
        productList: result,
      })

    },
    onTabsClick(event) {
      this.getProductsByCateId(event.detail.value)
    },
    jumpDetail(event) {
      console.log(event.currentTarget);
      const id = event.currentTarget.id;
      // switchTab tabBar页面跳转，navigateTo 非 tabBar页面跳转
      wx.navigateTo({
        url: `/pages/detail/detail?id=${id}`,
      });
    },

  },
});